<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Linux 三剑客  | YoiaL</title><meta name="keywords" content="学习笔记,菜鸟入门,Linux"><meta name="author" content="John Doe"><meta name="copyright" content="John Doe"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="linux 三剑客 find 、grep、sed整理 find 主要是用于查找Linux 操作系统的某个文件、目录所在路径，查找出满足条件的文件或者目录的路径. 命令格式: find data -option [ -print ] [ -exec -ok |lxargs lgrep ] [ command &amp;#123;&amp;#125;\; ]   date: 要査找的目彖路径 ~ 表示$HOME目录">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux 三剑客 ">
<meta property="og:url" content="https://liaoyia.gitee.io/2019/12/27/Linux-sed/index.html">
<meta property="og:site_name" content="YoiaL">
<meta property="og:description" content="linux 三剑客 find 、grep、sed整理 find 主要是用于查找Linux 操作系统的某个文件、目录所在路径，查找出满足条件的文件或者目录的路径. 命令格式: find data -option [ -print ] [ -exec -ok |lxargs lgrep ] [ command &amp;#123;&amp;#125;\; ]   date: 要査找的目彖路径 ~ 表示$HOME目录">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lyphotosnn3.png">
<meta property="article:published_time" content="2019-12-27T01:14:36.000Z">
<meta property="article:modified_time" content="2020-03-14T06:35:45.781Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="学习笔记">
<meta property="article:tag" content="菜鸟入门">
<meta property="article:tag" content="Linux">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lyphotosnn3.png"><link rel="shortcut icon" href="/liaoyia/img/favicon.png"><link rel="canonical" href="https://liaoyia.gitee.io/2019/12/27/Linux-sed/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/liaoyia/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/liaoyia/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":1,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-center"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2020-03-14 14:35:45'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><link rel="stylesheet" href="/css/fishes.css"><style type="text/css">#toggle-sidebar { left : 100px }</style><meta name="generator" content="Hexo 5.4.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="/liaoyia/null" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/liaoyia/archives/"><div class="headline">文章</div><div class="length-num">16</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/liaoyia/tags/"><div class="headline">标签</div><div class="length-num">9</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/liaoyia/categories/"><div class="headline">分类</div><div class="length-num">6</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/liaoyia/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa-fw fas fa-compass"></i><span> 目录</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/liaoyia/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page" href="/liaoyia/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page" href="/liaoyia/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa-fw fa fa-heartbeat"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/liaoyia/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page" href="/liaoyia/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li><li><a class="site-page" href="/liaoyia/books/"><i class="fa-fw fa fa-book"></i><span> 书籍</span></a></li><li><a class="site-page" href="/liaoyia/games/"><i class="fa-fw fa fa-gamepad"></i><span> 游戏</span></a></li><li><a class="site-page" href="/liaoyia/ziyu/"><i class="fa-fw fa-fw fas fa-cubes"></i><span> 自言自语</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw laptop-code"></i><span> 🎯</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/liaoyia/messages/"><i class="fa-fw fa-fw fas fa-comment-dots"></i><span> 留言板</span></a></li><li><a class="site-page" href="/liaoyia/link/"><i class="fa-fw fas fa-link"></i><span> Link</span></a></li><li><a class="site-page" href="/liaoyia/about/"><i class="fa-fw fa-fw fas fa-heart"></i><span> 关于我</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lyphotosnn3.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/liaoyia/">YoiaL</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/liaoyia/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa-fw fas fa-compass"></i><span> 目录</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/liaoyia/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page" href="/liaoyia/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page" href="/liaoyia/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa-fw fa fa-heartbeat"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/liaoyia/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page" href="/liaoyia/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li><li><a class="site-page" href="/liaoyia/books/"><i class="fa-fw fa fa-book"></i><span> 书籍</span></a></li><li><a class="site-page" href="/liaoyia/games/"><i class="fa-fw fa fa-gamepad"></i><span> 游戏</span></a></li><li><a class="site-page" href="/liaoyia/ziyu/"><i class="fa-fw fa-fw fas fa-cubes"></i><span> 自言自语</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw laptop-code"></i><span> 🎯</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/liaoyia/messages/"><i class="fa-fw fa-fw fas fa-comment-dots"></i><span> 留言板</span></a></li><li><a class="site-page" href="/liaoyia/link/"><i class="fa-fw fas fa-link"></i><span> Link</span></a></li><li><a class="site-page" href="/liaoyia/about/"><i class="fa-fw fa-fw fas fa-heart"></i><span> 关于我</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Linux 三剑客 </h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-12-27T01:14:36.000Z" title="发表于 2019-12-27 09:14:36">2019-12-27</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2020-03-14T06:35:45.781Z" title="更新于 2020-03-14 14:35:45">2020-03-14</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/liaoyia/categories/Linux/">Linux</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.5k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>9分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/hint.css/2.4.1/hint.min.css"><h1>linux 三剑客 find 、grep、sed整理</h1>
<h2 id="find">find</h2>
<p>主要是用于查找Linux 操作系统的某个文件、目录所在路径，查找出满足条件的文件或者目录的路径.</p>
<h2 id="命令格式">命令格式:</h2>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">find data -option [ -print ] [ -exec -ok |lxargs lgrep ] [ command &#123;&#125;\; ]</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<ol>
<li>
<p>date: 要査找的目彖路径<br>
~ 表示$HOME目录<br>
. 表示当前目彖<br>
/ 表示根目彖</p>
</li>
<li>
<p>print 表示输出结果标准输出</p>
</li>
<li>
<p>exec  対匹配的文件抉行垓参数所给出的shell命令，形式为 command {} ;   注意{}与;之同有空格</p>
</li>
<li>
<p>ok 与 exec 作用相同  执行命令前会提示确认是否执行</p>
</li>
<li>
<p>|xargs 与exec作用相同,起承接作用</p>
</li>
</ol>
<p>区別在于|xargs 主要用于承接刪除操作，而-exec都可用如复制丶移动丶重命名等。</p>
<h3 id="表示查找方式：">表示查找方式：</h3>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">-name filename     &#x2F; 查找名为filename的文件</span><br><span class="line"></span><br><span class="line">-perm              &#x2F; 按执行权限来查找</span><br><span class="line"></span><br><span class="line">-user username     &#x2F; 按文件属主来查找</span><br><span class="line"></span><br><span class="line">-group groupname   &#x2F; 按组来查找</span><br><span class="line"></span><br><span class="line">-mtime-n+n         &#x2F; 按文件更改时间来查找文件，-n指n天以内，+n指n天以前</span><br><span class="line"></span><br><span class="line">-atime-n+n         &#x2F; 按文件访问时间来查找文件，-n指n天以内，+n指n天以前</span><br><span class="line"></span><br><span class="line">-ctime-n+n         &#x2F; 按文件创建时间来查找文件，-n指n天以内，+n指n天以前</span><br><span class="line"></span><br><span class="line">-nogroup           &#x2F; 查无有效属组的文件，即文件的属组在&#x2F;etc&#x2F;groups中不存在</span><br><span class="line"></span><br><span class="line">-nouser            &#x2F; 查无有效属主的文件，即文件的属主在&#x2F;etc&#x2F;passwd中不存</span><br><span class="line"></span><br><span class="line">-type b&#x2F;d&#x2F;c&#x2F;p&#x2F;l&#x2F;f  &#x2F; 查是块设备、目录、字符设备、管道、符号链接、普通文件</span><br><span class="line"></span><br><span class="line">-size n[c]         &#x2F; 查长度为n块[或n字节】的文件</span><br><span class="line"></span><br><span class="line">-mount             &#x2F; 查文件时不跨越文件系统 mount点</span><br><span class="line"></span><br><span class="line">-follow            &#x2F; 如果遇到符号链接文件，就跟踪链接所指的文件</span><br><span class="line"></span><br><span class="line">-prune             &#x2F; 忽略某个目录</span><br></pre></td></tr></table></figure>
<p>实例:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">$        find . -name &quot;*.text&quot;   查找.text文件</span><br><span class="line"></span><br><span class="line">$        find ~ -name &quot;[a-z]*&quot;   以小写字母开头的文件</span><br><span class="line"></span><br><span class="line">$        find &#x2F; ! -type d        查找非文件夹</span><br><span class="line"></span><br><span class="line">$        find &#x2F;data&#x2F; -type l     查找链接文件</span><br><span class="line"></span><br><span class="line">$        find &#x2F;data&#x2F; -type d|xargs chmod 755 -R 查找目录类型并将权限设置755</span><br><span class="line"></span><br><span class="line">$        find &#x2F;data&#x2F; -size +1M   查找大于1M的文件</span><br><span class="line"></span><br><span class="line">$        find &#x2F;data&#x2F; -size 1M    查找1M的文件</span><br><span class="line"></span><br><span class="line">$        find &#x2F;data&#x2F; -mtime +30 -name &quot;*.log&quot;  查找30以前.log格式的文件</span><br><span class="line"></span><br><span class="line">    综合应用:</span><br><span class="line">$        find &#x2F;data&#x2F; -name &quot;*.log&quot; -type f -size +10m -exec cp&#123;&#125; &#x2F;tmp&#x2F; \;</span><br><span class="line"></span><br><span class="line">$        find &#x2F;data&#x2F; -name &quot;&quot; -type f -mtime +30 -size +10m -exec mv &#123;&#125; &#x2F;tmp&#x2F; \;</span><br></pre></td></tr></table></figure>
<h1>grep</h1>
<p>grep常用参数如下:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">-a        &#x2F;&#x2F; 以文本文件方式搜索</span><br><span class="line">-c        &#x2F;&#x2F; 计算找到的复合行的次数</span><br><span class="line">-n        &#x2F;&#x2F; 输出行号</span><br><span class="line">-v        &#x2F;&#x2F; 反选</span><br><span class="line">-h        &#x2F;&#x2F; 不显示文件名</span><br><span class="line">-l        &#x2F;&#x2F; 只输出包含匹配字符的文件名</span><br><span class="line">-i        &#x2F;&#x2F; 忽略大小写</span><br><span class="line">--color&#x3D;auto  &#x2F;&#x2F;颜色输出查找的关键字 &#x2F;&#x2F;color有三种参数（auto，always，never）</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>实例如下:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">$  grep -c &quot;root&quot;  &#x2F;etc&#x2F;passwd    统计root 的总行数</span><br><span class="line"></span><br><span class="line">$  grep -i  &quot;root&quot;  &#x2F;etc&#x2F;passwd   忽略大小写</span><br><span class="line"></span><br><span class="line">$  grep -n &quot;root&quot; &#x2F;etc&#x2F;passwd     打印root的行或者行号</span><br><span class="line"></span><br><span class="line">$  grep -v &quot;root&quot; &#x2F;etc&#x2F;passwd     不打印root的hang</span><br><span class="line"></span><br><span class="line">$  grep  &quot;root[53]&quot; &#x2F;etc&#x2F;passwd   以root开头的字符,接5或者3的行</span><br><span class="line"></span><br><span class="line">$  grep  &quot;^[^root]&quot; &#x2F;etc&#x2F;passwd   输出行首不是root的行</span><br><span class="line"></span><br><span class="line">$  grep  &quot;r\&#123;2,\&#125;&quot; &#x2F;etc&#x2F;passwd    打印r字符连续出现2次以上的行</span><br><span class="line"></span><br><span class="line">$  grep -n &quot;^$&quot; &#x2F;etc&#x2F;passwd       打印空行的所在行号</span><br><span class="line"></span><br><span class="line">$  grep --color -E &quot;\&gt;([0-9]&#123;1,3&#125;\.&#123;3&#125;)[0-9]&#123;1,3&#125;&quot;    匹配ipv4地址</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h1>sed</h1>
<p>sed [选项] ‘command’ file(s)</p>
<p>sed [选项] -f scriptfile file(s)</p>
<h3 id="常用参数">常用参数</h3>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">-e  &#x2F;&#x2F; 以指定的指令来处理输入的文本文件</span><br><span class="line"></span><br><span class="line">-n  &#x2F;&#x2F; 取消默认输出（如果和p命令同时使用只会打印发生改变的行）</span><br><span class="line"></span><br><span class="line">-h  &#x2F;&#x2F; 帮助</span><br><span class="line"></span><br><span class="line">-i  &#x2F;&#x2F; 会修改原文件  </span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="常用命令">常用命令</h3>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line">a   在当前行下面插入文本           i   在当前行上面插入文本 </span><br><span class="line"></span><br><span class="line">c   把选定的行改为新的文本         d   删除，删除选择的行 </span><br><span class="line"></span><br><span class="line">D   删除模板块的第一行             s   替换指定字符 </span><br><span class="line"></span><br><span class="line">h   拷贝模板块的内容到内存中的缓冲区</span><br><span class="line"></span><br><span class="line">H   追加模板块的内容到内存中的缓冲区 </span><br><span class="line"></span><br><span class="line">g   获得内存缓冲区的内容，并替代当前模板块中的文本 </span><br><span class="line"></span><br><span class="line">G   获得内存缓冲区的内容，并追加到当前模板块文本的后面 </span><br><span class="line"></span><br><span class="line">l   列表不能打印字符的清单 </span><br><span class="line"></span><br><span class="line">n   读取下一个输入行，用下一个命令处理新的行而不是用第一个命令 </span><br><span class="line"></span><br><span class="line">N   追加下一个输入行到模板块后面并在二者间嵌入一个新行，改变当前行号码 </span><br><span class="line"></span><br><span class="line">p   打印匹配的行 </span><br><span class="line"></span><br><span class="line">P   (大写)打印模板的第一行</span><br><span class="line"></span><br><span class="line">q   退出Sed </span><br><span class="line"></span><br><span class="line">b   lable 分支到脚本中带有标记的地方，如果分支不存在则分支到脚本的末尾 </span><br><span class="line"></span><br><span class="line">r   file 从file中读行 </span><br><span class="line"></span><br><span class="line">t   label if分支，从最后一行开始，条件一旦满足或者T，t命令，将导致分支到带有标号的命令处，或者到脚本的末尾 </span><br><span class="line"></span><br><span class="line">T   label 错误分支，从最后一行开始，一旦发生错误或者T，t命令，将导致分支到带有标号的命令处，或者到脚本的末尾 </span><br><span class="line"></span><br><span class="line">w   file 写并追加模板块到file末尾</span><br><span class="line"></span><br><span class="line">W   file 写并追加模板块的第一行到file末尾</span><br><span class="line"></span><br><span class="line">!   表示后面的命令对所有没有被选定的行发生作用 </span><br><span class="line"></span><br><span class="line">&#x3D;   打印当前行号码</span><br><span class="line"></span><br><span class="line">#   把注释扩展到下一个换行符以前</span><br></pre></td></tr></table></figure>
<h2 id="Sed替换命令">Sed替换命令</h2>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">g   表示行内全面替换（全局替换配合s命令使用）</span><br><span class="line"></span><br><span class="line">p   表示打印行 </span><br><span class="line"></span><br><span class="line">w   表示把行写入一个文件 </span><br><span class="line"></span><br><span class="line">x   表示互换模板块中的文本和缓冲区中的文本 </span><br><span class="line"></span><br><span class="line">y   表示把一个字符翻译为另外的字符（但是不用于正则表达式） </span><br><span class="line"></span><br><span class="line">\1  子串匹配标记 </span><br><span class="line"></span><br><span class="line">&amp;   已匹配字符串标记</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="Sed正则">Sed正则</h2>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">^        匹配行开始    如： &#x2F;^abc&#x2F;匹配所有已abc开头的行</span><br><span class="line"></span><br><span class="line">$        匹配行结束    如： &#x2F;abc$&#x2F;匹配所有已abc结尾的行</span><br><span class="line"></span><br><span class="line">.        匹配一个非换行符的任意字符    &#x2F;s.d&#x2F;</span><br><span class="line"> </span><br><span class="line">*        匹配0个或多个字符            &#x2F;*bc&#x2F;</span><br><span class="line"></span><br><span class="line">[]       匹配一个指定范围内的字符      &#x2F;[sS]ed&#x2F; 匹配sed和Sed </span><br><span class="line"></span><br><span class="line">[^]      匹配一个不在指定范围内的字符  &#x2F;[^A-FT-Y]bc 匹配不包含A-F和T-F一个字母开头，接着bc的行</span><br><span class="line"></span><br><span class="line">\(..\)   匹配子串</span><br><span class="line"></span><br><span class="line">&amp;        保存搜索字符用来替换其他字符</span><br><span class="line"></span><br><span class="line">\&lt;       匹配单词的开始</span><br><span class="line"></span><br><span class="line">\&gt;       匹配单词的结束</span><br><span class="line"></span><br><span class="line">x\&#123;m\&#125;   重复字符x，m次</span><br><span class="line"></span><br><span class="line">x\&#123;m,\&#125;   重复字符x，至少m次 </span><br><span class="line"></span><br><span class="line">x\&#123;m,n\&#125;  重复字符x，至少m次，不多于n次</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="Sed常用实例">Sed常用实例</h2>
<h3 id="1、替换操作">1、替换操作</h3>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">$ echo &quot;hello world&quot; |sed &#39;s&#x2F; &#x2F;-&#x2F;1g&#39;  从第一个空格开始全局替换成-，只不过文本中只有一个空格</span><br><span class="line"></span><br><span class="line">$ hello-world  </span><br></pre></td></tr></table></figure>
<h3 id="2、删除操作">2、删除操作</h3>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line">$ sed &#39;&#x2F;^$&#x2F;d&#39; filename       &#x2F;&#x2F; 删除空白行</span><br><span class="line"></span><br><span class="line">$ sed &#39;2d&#39; filename          &#x2F;&#x2F; 删除第二行</span><br><span class="line"></span><br><span class="line">$ sed &#39;2，$d&#39; filename       &#x2F;&#x2F; 删除第二直到未尾所有行</span><br><span class="line"></span><br><span class="line">$ sed &#39;$d&#39; filename          &#x2F;&#x2F; 删除最后一行</span><br><span class="line"></span><br><span class="line">$ sed &#39;&#x2F;^test&#x2F;&#39;d filename    &#x2F;&#x2F; 删除以test开头行</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="3、匹配的替换">3、匹配的替换</h2>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">$ echo &quot;hello world&quot; |sed &#39;s&#x2F;\w\+&#x2F;[&amp;]&#x2F;g&#39;   </span><br><span class="line">[hello] [world]</span><br><span class="line">## \w+匹配每一个单词，&amp;表示匹配到的字符串</span><br><span class="line"></span><br><span class="line">$ echo &quot;hello world&quot; |sed &#39;s&#x2F;\w\+&#x2F;&quot;&amp;&quot;&#x2F;g&#39;</span><br><span class="line"></span><br><span class="line">“hello” “world”</span><br></pre></td></tr></table></figure>
<h2 id="4、选定范围">4、选定范围</h2>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">$ sed -n &#39;&#x2F;&#x3D; 0&#x2F;,&#x2F;max&#x2F;p&#39; s.conf   &#x2F;&#x2F; 所有在&#x3D;0到max范围内的行都会被打印出来</span><br><span class="line"></span><br><span class="line">min-encryption &#x3D; 0</span><br><span class="line"></span><br><span class="line">max-encryption &#x3D; 256</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h2 id="5、读入与写入">5、读入与写入</h2>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line">[root@centos001 ~]#cat test1</span><br><span class="line"></span><br><span class="line">welcom </span><br><span class="line"></span><br><span class="line">to </span><br><span class="line"></span><br><span class="line">here</span><br><span class="line"></span><br><span class="line">[root@centos001 ~]#sed &#39;&#x2F;here&#x2F;r test1&#39; test</span><br><span class="line"></span><br><span class="line">this is a test file</span><br><span class="line"></span><br><span class="line">welcome</span><br><span class="line"></span><br><span class="line">to</span><br><span class="line"></span><br><span class="line">here</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#welcom </span><br><span class="line"></span><br><span class="line">to </span><br><span class="line"></span><br><span class="line">here#</span><br><span class="line"></span><br><span class="line">hello WORLD</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">linux centos6.8</span><br><span class="line"></span><br><span class="line">redhat</span><br><span class="line"></span><br><span class="line">#将test1的文件内容读取显示所有匹配here行的后面</span><br><span class="line"></span><br><span class="line">sed -n &#39;&#x2F;centos6.8&#x2F;w test2&#39; test</span><br><span class="line"></span><br><span class="line">[root@centos001 ~]#cat test2</span><br><span class="line"></span><br><span class="line">linux centos6.8</span><br><span class="line"></span><br><span class="line">#将test文件匹配到centos6.8的所有行都写入到test2文件中，文件可以不存在</span><br><span class="line"></span><br><span class="line">#如果文件存在，就会被重定向不是追加</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="6、追加与插入">6、追加与插入</h3>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">[root@centos001 ~]#sed &#39;&#x2F;^l&#x2F;a\2017-08-08&#39; test2</span><br><span class="line"></span><br><span class="line">linux centos6.8</span><br><span class="line"></span><br><span class="line">2017-08-08</span><br><span class="line"></span><br><span class="line">#在匹配以l开头的行的后面追加2017-08-08</span><br><span class="line"></span><br><span class="line">[root@centos001 ~]#sed &#39;1a\2017-08-08&#39; test2</span><br><span class="line"></span><br><span class="line">linux centos6.8</span><br><span class="line"></span><br><span class="line">2017-08-08</span><br><span class="line"></span><br><span class="line">#在第一行的后面追加2017-08-08</span><br><span class="line"></span><br><span class="line">[root@centos001 ~]#sed &#39;&#x2F;^l&#x2F;i\2017-08-08&#39; test2</span><br><span class="line"></span><br><span class="line">2017-08-08</span><br><span class="line"></span><br><span class="line">linux centos6.8</span><br><span class="line"></span><br><span class="line">#在匹配以l开头的行的前面插入2017-08-08</span><br><span class="line"></span><br><span class="line">#######以上操作是不会改变文件内容################</span><br><span class="line"></span><br><span class="line">[root@centos001 ~]#sed -i &#39;&#x2F;^l&#x2F;i\2017-08-08&#39; test2</span><br><span class="line"></span><br><span class="line">[root@centos001 ~]#cat test2</span><br><span class="line"></span><br><span class="line">2017-08-08</span><br><span class="line"></span><br><span class="line">linux centos6.8</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="7、其它命令实例">7、其它命令实例</h3>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">[root@centos001 ~]#cat -n test2</span><br><span class="line"></span><br><span class="line">     1	2017-08-08</span><br><span class="line"></span><br><span class="line">     2	linux centos6.8</span><br><span class="line"></span><br><span class="line">     3	08</span><br><span class="line"></span><br><span class="line">     4	</span><br><span class="line"></span><br><span class="line">     5	test</span><br><span class="line"></span><br><span class="line">[root@centos001 ~]#sed &#39;&#x2F;08&#x2F;&#123; n; s&#x2F;l&#x2F;L&#x2F;; &#125;&#39; test2</span><br><span class="line"></span><br><span class="line">2017-08-08</span><br><span class="line"></span><br><span class="line">Linux centos6.8</span><br><span class="line"></span><br><span class="line">08</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">test</span><br><span class="line"></span><br><span class="line">#如果08匹配到就跳到下一行，将小写l替换成大写，注意到第三行也是被匹配到</span><br><span class="line"></span><br><span class="line">但是后面的条件不满足，所有没有被替换</span><br><span class="line"></span><br><span class="line">[root@centos001 ~]#sed &#39;1,4y&#x2F;8&#x2F;9&#x2F;&#39; test2</span><br><span class="line"></span><br><span class="line">2017-09-09</span><br><span class="line"></span><br><span class="line">linux centos6.9</span><br><span class="line"></span><br><span class="line">09</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">test</span><br><span class="line"></span><br><span class="line">#将1至4行所有的数字8替换成9</span><br><span class="line"></span><br><span class="line">[root@centos001 ~]#sed &#39;1q&#39; test2</span><br><span class="line"></span><br><span class="line">2017-08-08</span><br><span class="line"></span><br><span class="line">#打印第一行内容后退出</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="8、打印奇数或公偶数行">8、打印奇数或公偶数行</h3>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">[root@centos001 ~]#sed -n &#39;p;n&#39; test2</span><br><span class="line"></span><br><span class="line">20170808</span><br><span class="line"></span><br><span class="line">08</span><br><span class="line"></span><br><span class="line">[root@centos001 ~]#sed -n &#39;n;p&#39; test2</span><br><span class="line"></span><br><span class="line">linux centos6.8</span><br><span class="line"></span><br><span class="line">test</span><br><span class="line"></span><br><span class="line">[root@centos001 ~]#sed -n &#39;1~2p&#39; test2</span><br><span class="line"></span><br><span class="line">20170808</span><br><span class="line"></span><br><span class="line">08</span><br><span class="line"></span><br><span class="line">[root@centos001 ~]#sed -n &#39;2~2p&#39; test2</span><br><span class="line"></span><br><span class="line">linux centos6.8</span><br><span class="line"></span><br><span class="line">test</span><br></pre></td></tr></table></figure>
<h3 id="9、打印匹配字符串行的下一行">9、打印匹配字符串行的下一行</h3>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line">[root@centos001 ~]#sed -n &#39;&#x2F;linux&#x2F;&#123;n;p&#125;&#39; test2</span><br><span class="line"></span><br><span class="line">08</span><br><span class="line"></span><br><span class="line">[root@centos001 ~]#awk &#39;&#x2F;linux&#x2F;&#123;getline; print&#125;&#39; test2</span><br><span class="line"></span><br><span class="line">08</span><br><span class="line"></span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:null">John Doe</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://liaoyia.gitee.io/2019/12/27/Linux-sed/">https://liaoyia.gitee.io/2019/12/27/Linux-sed/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://liaoyia.gitee.io" target="_blank">YoiaL</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/liaoyia/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">学习笔记</a><a class="post-meta__tags" href="/liaoyia/tags/%E8%8F%9C%E9%B8%9F%E5%85%A5%E9%97%A8/">菜鸟入门</a><a class="post-meta__tags" href="/liaoyia/tags/Linux/">Linux</a></div><div class="post_share"><div class="social-share" data-image="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lyphotosnn3.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/liaoyia/2020/03/22/MySQL%E5%88%9B%E5%BB%BA%E5%92%8C%E7%AE%A1%E7%90%86%E6%95%B0%E6%8D%AE%E5%BA%93/"><img class="prev-cover" src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lymonvpng.png" onerror="onerror=null;src='/liaoyia/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">初探 MySQL</div></div></a></div><div class="next-post pull-right"><a href="/liaoyia/2019/12/12/Git/"><img class="next-cover" src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lygit.png" onerror="onerror=null;src='/liaoyia/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">初探 Git</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/liaoyia/2019/12/11/shell/" title="Shell初探"><img class="cover" src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lybash.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-12-11</div><div class="title">Shell初探</div></div></a></div><div><a href="/liaoyia/2019/11/15/linux-文件权限/" title="Linux 文件权限"><img class="cover" src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lyphotos677.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-15</div><div class="title">Linux 文件权限</div></div></a></div><div><a href="/liaoyia/2019/11/12/Linux-网络配置/" title="Iinux 网络配置"><img class="cover" src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lylinux.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-12</div><div class="title">Iinux 网络配置</div></div></a></div><div><a href="/liaoyia/2020/06/26/MySQL基础/" title="Mysql回顾"><img class="cover" src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lymysql.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-06-26</div><div class="title">Mysql回顾</div></div></a></div><div><a href="/liaoyia/2020/06/22/css层叠样式表/" title="Css层叠样式表期末复习"><img class="cover" src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lyHTML.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-06-22</div><div class="title">Css层叠样式表期末复习</div></div></a></div><div><a href="/liaoyia/2020/04/29/MySQL表查询实训笔记/" title="MySQL表查询实训"><img class="cover" src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lymonvpng.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-04-29</div><div class="title">MySQL表查询实训</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="/liaoyia/null" onerror="this.onerror=null;this.src='/liaoyia/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">John Doe</div><div class="author-info__description"></div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/liaoyia/archives/"><div class="headline">文章</div><div class="length-num">16</div></a></div><div class="card-info-data-item is-center"><a href="/liaoyia/tags/"><div class="headline">标签</div><div class="length-num">9</div></a></div><div class="card-info-data-item is-center"><a href="/liaoyia/categories/"><div class="headline">分类</div><div class="length-num">6</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/liaoyio" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="/liaoyia/2417276459" target="_blank" title="QQ"><i class="fas fa-qq"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">1.</span> <span class="toc-text">linux 三剑客 find 、grep、sed整理</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#find"><span class="toc-number">1.1.</span> <span class="toc-text">find</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%91%BD%E4%BB%A4%E6%A0%BC%E5%BC%8F"><span class="toc-number">1.2.</span> <span class="toc-text">命令格式:</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A1%A8%E7%A4%BA%E6%9F%A5%E6%89%BE%E6%96%B9%E5%BC%8F%EF%BC%9A"><span class="toc-number">1.2.1.</span> <span class="toc-text">表示查找方式：</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">2.</span> <span class="toc-text">grep</span></a></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">3.</span> <span class="toc-text">sed</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E5%8F%82%E6%95%B0"><span class="toc-number">3.0.1.</span> <span class="toc-text">常用参数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4"><span class="toc-number">3.0.2.</span> <span class="toc-text">常用命令</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Sed%E6%9B%BF%E6%8D%A2%E5%91%BD%E4%BB%A4"><span class="toc-number">3.1.</span> <span class="toc-text">Sed替换命令</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Sed%E6%AD%A3%E5%88%99"><span class="toc-number">3.2.</span> <span class="toc-text">Sed正则</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Sed%E5%B8%B8%E7%94%A8%E5%AE%9E%E4%BE%8B"><span class="toc-number">3.3.</span> <span class="toc-text">Sed常用实例</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1%E3%80%81%E6%9B%BF%E6%8D%A2%E6%93%8D%E4%BD%9C"><span class="toc-number">3.3.1.</span> <span class="toc-text">1、替换操作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81%E5%88%A0%E9%99%A4%E6%93%8D%E4%BD%9C"><span class="toc-number">3.3.2.</span> <span class="toc-text">2、删除操作</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3%E3%80%81%E5%8C%B9%E9%85%8D%E7%9A%84%E6%9B%BF%E6%8D%A2"><span class="toc-number">3.4.</span> <span class="toc-text">3、匹配的替换</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4%E3%80%81%E9%80%89%E5%AE%9A%E8%8C%83%E5%9B%B4"><span class="toc-number">3.5.</span> <span class="toc-text">4、选定范围</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5%E3%80%81%E8%AF%BB%E5%85%A5%E4%B8%8E%E5%86%99%E5%85%A5"><span class="toc-number">3.6.</span> <span class="toc-text">5、读入与写入</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#6%E3%80%81%E8%BF%BD%E5%8A%A0%E4%B8%8E%E6%8F%92%E5%85%A5"><span class="toc-number">3.6.1.</span> <span class="toc-text">6、追加与插入</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7%E3%80%81%E5%85%B6%E5%AE%83%E5%91%BD%E4%BB%A4%E5%AE%9E%E4%BE%8B"><span class="toc-number">3.6.2.</span> <span class="toc-text">7、其它命令实例</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8%E3%80%81%E6%89%93%E5%8D%B0%E5%A5%87%E6%95%B0%E6%88%96%E5%85%AC%E5%81%B6%E6%95%B0%E8%A1%8C"><span class="toc-number">3.6.3.</span> <span class="toc-text">8、打印奇数或公偶数行</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9%E3%80%81%E6%89%93%E5%8D%B0%E5%8C%B9%E9%85%8D%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%A1%8C%E7%9A%84%E4%B8%8B%E4%B8%80%E8%A1%8C"><span class="toc-number">3.6.4.</span> <span class="toc-text">9、打印匹配字符串行的下一行</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/liaoyia/2020/11/12/hello-world/" title="Hello World"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/liaoyia/img/404.jpg'" alt="Hello World"/></a><div class="content"><a class="title" href="/liaoyia/2020/11/12/hello-world/" title="Hello World">Hello World</a><time datetime="2020-11-12T05:23:35.000Z" title="发表于 2020-11-12 13:23:35">2020-11-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/liaoyia/2020/06/26/MySQL%E5%9F%BA%E7%A1%80/" title="Mysql回顾"><img src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lymysql.jpg" onerror="this.onerror=null;this.src='/liaoyia/img/404.jpg'" alt="Mysql回顾"/></a><div class="content"><a class="title" href="/liaoyia/2020/06/26/MySQL%E5%9F%BA%E7%A1%80/" title="Mysql回顾">Mysql回顾</a><time datetime="2020-06-26T12:34:53.000Z" title="发表于 2020-06-26 20:34:53">2020-06-26</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/liaoyia/2020/06/22/css%E5%B1%82%E5%8F%A0%E6%A0%B7%E5%BC%8F%E8%A1%A8/" title="Css层叠样式表期末复习"><img src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lyHTML.png" onerror="this.onerror=null;this.src='/liaoyia/img/404.jpg'" alt="Css层叠样式表期末复习"/></a><div class="content"><a class="title" href="/liaoyia/2020/06/22/css%E5%B1%82%E5%8F%A0%E6%A0%B7%E5%BC%8F%E8%A1%A8/" title="Css层叠样式表期末复习">Css层叠样式表期末复习</a><time datetime="2020-06-22T11:08:56.000Z" title="发表于 2020-06-22 19:08:56">2020-06-22</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/liaoyia/2020/04/29/MySQL%E8%A1%A8%E6%9F%A5%E8%AF%A2%E5%AE%9E%E8%AE%AD%E7%AC%94%E8%AE%B0/" title="MySQL表查询实训"><img src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lymonvpng.png" onerror="this.onerror=null;this.src='/liaoyia/img/404.jpg'" alt="MySQL表查询实训"/></a><div class="content"><a class="title" href="/liaoyia/2020/04/29/MySQL%E8%A1%A8%E6%9F%A5%E8%AF%A2%E5%AE%9E%E8%AE%AD%E7%AC%94%E8%AE%B0/" title="MySQL表查询实训">MySQL表查询实训</a><time datetime="2020-04-29T08:21:56.000Z" title="发表于 2020-04-29 16:21:56">2020-04-29</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/liaoyia/2020/04/09/MySQL%E6%95%B0%E6%8D%AE%E6%9B%B4%E6%96%B0/" title="MySQL数据更新和单表查询"><img src="https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lysee.png" onerror="this.onerror=null;this.src='/liaoyia/img/404.jpg'" alt="MySQL数据更新和单表查询"/></a><div class="content"><a class="title" href="/liaoyia/2020/04/09/MySQL%E6%95%B0%E6%8D%AE%E6%9B%B4%E6%96%B0/" title="MySQL数据更新和单表查询">MySQL数据更新和单表查询</a><time datetime="2020-04-09T08:08:56.000Z" title="发表于 2020-04-09 16:08:56">2020-04-09</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://cdn.jsdelivr.net/gh/liaoyio/imgHosting/img-lyphotosnn3.png')"><div id="footer-wrap"><div class="copyright">&copy;2018 - 2021 <i style="color:#FF6A6A" class="fa fa-heartbeat"></i> John Doe</div><div class="footer_custom_text">Hi, welcome to my <a target="_blank" rel="noopener" href="https://liaoyi.xyz/">blog</a>!</div></div><div class="container" id="jsi-flying-fish-container"></div><script src="js/fish.js"></script><style>@media only screen and (max-width: 767px){
#sidebar_search_box input[type=text]{width:calc(100% - 24px)}
}</style></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/liaoyia/js/utils.js"></script><script src="/liaoyia/js/main.js"></script><script src="/liaoyia/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script src="/liaoyia/js/search/local-search.js"></script><div class="js-pjax"></div><script src="https://cdn.jsdelivr.net/gh/sviptzk/HexoStaticFile@latest/Hexo/js/mouse_snow.min.js"></script><script src="js/jquery.min.js"></script><script src="/js/fish.js"></script><div class="aplayer no -destroy" data-id="000PeZCQ1i4XVs" data-server="tencent" data-type="artist" data-fixed="true" data-mini=" true" data-listFolded="false" data-order="random" data-preload="none" data-autoplay="true" muted></div><script src="/js/fishes.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="true"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>